package com.rub.android.ui.fragment

import android.os.Bundle
import com.lxj.xpopup.core.BasePopupView
import com.rub.android.R
import com.rub.android.base.BaseFragment
import com.rub.android.utils.gone
import com.rub.android.widget.OpenFLEvent
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 * 参考文章
 * https://blog.csdn.net/BigBoySunshine/article/details/105774561
 */
class HomeFragment : BaseFragment() {
    //打开福利
    private var selectSourceDialog: BasePopupView? = null

    private var openFL = false

    override fun getLayoutId(): Int = R.layout.fragment_home_new

    override fun initTitleBar(titleBar: CommonTitleBar?) {
       /* titleBar?.run {
            centerSearchRightImageView.gone()
            setListener { v, action, extra ->
                when (action) {
                    CommonTitleBar.ACTION_SEARCH -> {
                    }
                }
            }
        }*/
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun initListener() {
        super.initListener()

    }

    override fun initData() {
        super.initData()

    }

    override fun initView() {
        super.initView()

    }

    override fun onStart() {
        super.onStart()
        EventBus.getDefault().register(this)
    }

    override fun onStop() {
        super.onStop()
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    fun onMessageEvent(event: OpenFLEvent) {
        if (openFL == event.open) {
            //与当前一样，return
            return
        }
        openFL = event.open
        //不一样时重新加载数据
        initData()
    }

}
